<template>
  <div style="min-height: 700px">
    <a-card :bordered="false" title style="min-height: 700px">
      <a-card :bordered="false" style="min-height: 700px" title="常规设置">
        <!--  -->

        <a-collapse v-model="activeKey" default-active-key="1">
          <a-collapse-panel key="1" header="修改密码">
            <div style="width: 500px; margin: 0 auto">
              <!-- <h4>当前密码 <span style="color: red">*</span></h4>
              <div style="height: 10px"></div>
              <a-input
                placeholder="输入当前密码"
                style="width: 464.95px"
                v-model="password.old"
                type="password"
              /> -->
              <div style="height: 10px"></div>
              <h4>新密码 <span style="color: red">*</span></h4>
              <div style="height: 10px"></div>
              <a-input-password
                placeholder="请输入新密码"
                style="width: 464.95px"
                v-model="password.new1"
                type="password"
              >
                <a-icon slot="prefix" type="lock" />
              </a-input-password>
              <div style="height: 10px"></div>
              <a-input-password
                placeholder="重复上面的新密码"
                style="width: 464.95px"
                v-model="password.new2"
                type="password"
              >
                <a-icon slot="prefix" type="lock" />
              </a-input-password>
              <div style="height: 15px"></div>
              <a-button type="primary" @click="submit">提交</a-button>
              <a-button @click="cancel()" style="margin-left: 10px">
                取消
              </a-button>
            </div>
          </a-collapse-panel>
        </a-collapse>
      </a-card>
    </a-card>
  </div>
</template>

<script>
import { CommonAjax } from "@/services/modules/common.js";
const commonAjax = new CommonAjax();

export default {
  data() {
    return {
      activeKey: ["1"],
      password: {
        // old: "",
        new1: "",
        new2: "",
      },
    };
  },
  methods: {
    // 提交按钮
    submit() {
      console.log(" --- this.password --- ", this.password);
      const { new1, new2 } = this.password;
      if (new1 === new2 && new1 !== "888888") {
        const option = `workNo=${this.$store.state.user.info.workNo}&password=${new1}`;
        commonAjax.passwordChange(option).then((res) => {
          if (!res.success) {
            this.$message.error(res.message);
            this.$message.error("请刷新页面重试");
            return;
          }
          this.$message.success(res.message);
          setTimeout(this.$router.push("/login"), 500);
        });
      } else if (new1 !== new2) {
        this.$message.error("两遍密码不一致");
      } else if (new1 === new2 && new1 === "888888") {
        this.$message.error("禁止设置默认密码");
      }
    },
    cancel() {
      this.$router.push("/login");
    },
    //  取消显示对应 key 的折叠面板
    // cancel(key) {
    //   let activeKey = this.activeKey;
    //   activeKey = activeKey.filter((item) => item !== key);
    //   this.activeKey = activeKey;
    // },
  },
};
</script>

<style >
</style>